package ar.edu.unju.fi.uicomponents.converters;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;


@FacesConverter("ConverterNumber")
public class ConverterNumber implements Converter {
	
	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		Integer documento ;
	
		try{
			documento = Integer.parseInt(arg2);	
		}catch (NumberFormatException e ) {
			FacesMessage msg = 	new FacesMessage("Documento invalido", "Ingrese un valor numerico......");
			msg.setSeverity(FacesMessage.SEVERITY_ERROR);
			
			throw new ConverterException(msg);	 
			
		}		
		return documento;

	}
	
	

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {

		return arg2.toString();
	}
	
	

}
